package com.senseuni.da.ui.dialog;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.senseuni.common.dialog.CBDialogBuilder;
import com.senseuni.da.R;
import com.senseuni.da.utils.QRCodeUtil;

public class AddFriendDialog extends CBDialogBuilder {

    private ImageView mImageView;

    public AddFriendDialog(Context context) {
        super(context, CBDialogBuilder.DIALOG_STYLE_NORMAL, (float) 0.4);
        initView(context);
    }

    public AddFriendDialog setQRCode(String code) {
        if (mImageView != null) {
            Bitmap bitmap = QRCodeUtil.createQRCodeBitmap(code, 200, 200);
            mImageView.setImageBitmap(bitmap);
        }
        return this;
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_add_friend, null);
        mImageView = view.findViewById(R.id.image_view);
        setView(view);
        setTouchOutSideCancelable(false);
        showCancelButton(true);
        setButtonClickListener(false, (context1, dialog, whichBtn) -> {
            dialog.dismiss();
        });
    }

}
